import { logger } from '../../../../common';
import { AgentContext } from '../agentContext';
export abstract class AgentState {

  public name: string;
  public context: AgentContext;

  constructor(name: string) { this.name = name; }

  public getStateName() {
    return this.name;
  }

  private callerName() {
    try {
      throw new Error();
    }
    catch (e) {
      try {
        return e.stack.split('at ')[3].split(' ')[0];
      } catch (e) {
        return '';
      }
    }
  }

  protected warnJump() {
    const callingFunctionName = this.callerName();
    logger.warn(`current state is: ${this.context.getCurrentStateName()}, can not call ${callingFunctionName}.`);
  }

  public setContext(context: AgentContext) {
    this.context = context;
  }

  public abstract establishConnection(): Promise<void>;
  public abstract registerAbilities(): Promise<void>;
  public abstract onSimulationRequest(): Promise<void>;
}